package com.sjh.sjhliving.commodity.controller;


import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSClientBuilder;
import com.sjh.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

@RestController
@Slf4j
public class TestController {


    @RequestMapping(value = "/test")
    public R testUpload() throws FileNotFoundException{
        log.info("test Upload");
        String endpoint = "oss-cn-beijing.aliyuncs.com";
        String accessKeyId = "LTAI5tQuKcWdcek6ZmaaWRfm";
        String accessKeySecret = "uxtFFGgymPRLTCNLkpVYrakFJh68Od";
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        InputStream inputStream = new
                FileInputStream("D:\\1.jpg");
        ossClient.putObject("sjhliving-10001", "1.jpg", inputStream);
        ossClient.shutdown();
        return null;
    }


    @Resource
    private OSSClient ossClient;

    @RequestMapping("/test2")
    public R testUpload2() throws FileNotFoundException {
        log.info("test Upload2");
        InputStream inputStream =
                new FileInputStream("D:\\2.jpg");
        ossClient.putObject("sjhliving-10001", "2.jpg", inputStream);
        ossClient.shutdown();
        System.out.println("上传 ok~");
        return null;
    }
}
